<?php
/**
 * Copyright 2007 Melange.
 *
 * This file is part of PHP-MVC.
 *
 * PHP-MVC is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * PHP-MVC is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with PHP-MVC; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * @category    Melange
 * @package     php-mvc/view
 * @subpackage  form
 * @copyright   Copyright (c) 2007 Jeroen Simons. All rights reserved
 * @author      Jeroen Simons <jeroen@melange.nl>
 * @link        http://www.melange.nl/
 *
 */

require_once 'mvc/view/helper/zend/FormSelect.php';

class PHP_MVC_View_Form_Helper_FormHours extends Zend_View_Helper_FormSelect {

    private static $hours = array(
        ""=>"--",
        "00"=>"00", "01"=>"01", "02"=>"02", "03"=>"03", "04"=>"04", "05"=>"05", "06"=>"06", "07"=>"07", "08"=>"08", "09"=>"09",
        "10"=>"10", "11"=>"11", "12"=>"12", "13"=>"13", "14"=>"14", "15"=>"15", "16"=>"16", "17"=>"17", "18"=>"18", "19"=>"19",
        "20"=>"20", "21"=>"21", "22"=>"22", "23"=>"23"
    );
    
    public function formHours($name, $value = null, $attribs = null)
    {
        // Override the class if error (Made global in ActionController) exists for this field.
        $actionErrors = $this->pageContext->request->getAttribute(MVC::ERROR_KEY);
        if(!is_null($actionErrors) && !$actionErrors->isEmpty() && !is_null($actionErrors->get($name))) {
            $attribs["class"] = "error";
        }

        return parent::formSelect($name, $value, $attribs, self::$hours);
    }
}
?>